package com.my.controller.System;


import com.my.bean.SysDic;
import com.my.bean.ZtreeBean;
import com.my.service.SysDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2018-08-20
 */
@Controller
@RequestMapping("/sysDic")
public class SysDicController {
    @Autowired
    SysDicService sysDicService;
     //跳转到字典表主页面
    @RequestMapping("/index")
    public  String index(){
        return "/System/dic";
    }
    @RequestMapping("/insertDic")
    @ResponseBody
    public boolean index(SysDic sysDic){
        sysDic.setCreateTime(new Date().getTime());
        return sysDicService.insert(sysDic);
    }
//查询出所有ztree需要的树数据
    @RequestMapping("/selectDic")
    @ResponseBody
    public List<ZtreeBean> selectDic(SysDic sysDic){
        List<ZtreeBean> list=sysDicService.selectDic();
        return list;
    }
    //查询树的所有信息   根据id
    @RequestMapping("/selectDicById")
    @ResponseBody
    public SysDic selectDicById(SysDic sysDic){
        SysDic sysDicPojo=sysDicService.selectDicById(sysDic.getId());
        return sysDicPojo;
    }
    //根据id删除节点 如果有子节点 则连带删除
    @RequestMapping("/deletById")
    @ResponseBody

    public String deletById(SysDic sysDic) {
       if (sysDicService.deletAllDicById(sysDic)){
           return "删除成功";
       }else{
           return  "删除失败";
       }
    }
   /*public  boolean deletById(SysDic sysDic){
       return
    }*/


    //根据code查询字典表子节点
    @RequestMapping("/findDataByDicCode")
    @ResponseBody
    public List<SysDic> findDataByDicCode(String code) {
      return   sysDicService.findDataByDicCode(code);
    }
}
